﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using WebApplication1.API返回类;
using WebApplication1.Models.商品信息.企业;
using WebApplication1.Models.商品信息.深加工;

namespace WebApplication1.Controllers
{
    /// <summary>
    /// 深加工控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeepController : ControllerBase
    {
        private readonly ISqlSugarClient _db;

        public DeepController(SqlSugar.ISqlSugarClient db)
        {
            this._db = db;
        }


        //------------------------------------------------深加工DeepModel----------------------------------------------------------------------
        /// <summary>
        /// 创建深加工信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateDeep(DeepModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建深加工信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建深加工信息失败");
            }
        }

        /// <summary>
        /// 查询深加工信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<DeepModel>> GetDeepAll(int id)
        {
            var list = _db.Queryable<DeepModel>().Where(x => x.RId == id).OrderByDescending(x => x.DeepId);

            return new APIResult<List<DeepModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询深加工信息成功",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------食品安全图片FoodSafetyModel-------------------------------------------------------------------
        /// <summary>
        /// 创建食品安全信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateFoodSafety(FoodSafetyModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建食品安全信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建食品安全信息失败");
            }
        }

        /// <summary>
        /// 查询食品安全信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<FoodSafetyModel>> GetFoodSafetyAll(int id)
        {
            var list = _db.Queryable<FoodSafetyModel>().Where(x => x.RId == id).OrderByDescending(x => x.FoodSafetyId);

            return new APIResult<List<FoodSafetyModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询食品安全信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------原料信息FeedstockModel-------------------------------------------------------------------
        /// <summary>
        /// 创建原料信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateFeedstock(FeedstockModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建原料信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建原料信息失败");
            }
        }

        /// <summary>
        /// 查询原料信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<FeedstockModel>> GetFeedstockAll(int id)
        {
            var list = _db.Queryable<FeedstockModel>().Where(x => x.RId == id).OrderByDescending(x => x.FeedstockId);

            return new APIResult<List<FeedstockModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询原料信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------原料图片信息FeedstockpicModel-------------------------------------------------------------------
        /// <summary>
        /// 创建原料图片
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateFeedstockpic(FeedstockpicModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建原料图片成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建原料图片失败");
            }
        }

        /// <summary>
        /// 查询原料图片
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<FeedstockpicModel>> GetFeedstockpicAll(int id)
        {
            var list = _db.Queryable<FeedstockpicModel>().Where(x => x.RId == id).OrderByDescending(x => x.FeedstockpicId);

            return new APIResult<List<FeedstockpicModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询原料图片",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------辅料信息AdditiveModel-------------------------------------------------------------------
        /// <summary>
        /// 创建辅料信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateAdditive(AdditiveModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建辅料信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建原料图片失败");
            }
        }

        /// <summary>
        /// 查询辅料信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<AdditiveModel>> GetAdditiveAll(int id)
        {
            var list = _db.Queryable<AdditiveModel>().Where(x => x.RId == id).OrderByDescending(x => x.AdditiveId);

            return new APIResult<List<AdditiveModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询辅料信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------辅料图片AdditivepicModel-------------------------------------------------------------------
        /// <summary>
        /// 创建辅料信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateAdditivepic(AdditivepicModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建辅料信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建原料图片失败");
            }
        }

        /// <summary>
        /// 查询辅料信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<AdditivepicModel>> GetAdditivepicAll(int id)
        {
            var list = _db.Queryable<AdditivepicModel>().Where(x => x.RId == id).OrderByDescending(x => x.AdditivepicId);

            return new APIResult<List<AdditivepicModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询辅料信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------添加剂MaterialModel-------------------------------------------------------------------
        /// <summary>
        /// 创建添加剂信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateMaterial(MaterialModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建添加剂信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建添加剂信息失败");
            }
        }

        /// <summary>
        /// 查询添加剂信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<MaterialModel>> GetMaterialAll(int id)
        {
            var list = _db.Queryable<MaterialModel>().Where(x => x.RId == id).OrderByDescending(x => x.MaterialId);

            return new APIResult<List<MaterialModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询添加剂信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------添加剂图片MaterialpicModel-------------------------------------------------------------------
        /// <summary>
        /// 创建添加剂图片
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateMaterialpic(MaterialpicModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建添加剂图片成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建添加剂图片失败");
            }
        }

        /// <summary>
        /// 查询添加剂信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<MaterialpicModel>> GetMaterialpicAll(int id)
        {
            var list = _db.Queryable<MaterialpicModel>().Where(x => x.RId == id).OrderByDescending(x => x.MaterialpicId);

            return new APIResult<List<MaterialpicModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询添加剂图片",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------包材PackagingModel-------------------------------------------------------------------
        /// <summary>
        /// 创建包材信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreatePackaging(PackagingModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建包材信息成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建包材信息失败");
            }
        }

        /// <summary>
        /// 查询包材信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<PackagingModel>> GetPackagingAll(int id)
        {
            var list = _db.Queryable<PackagingModel>().Where(x => x.RId == id).OrderByDescending(x => x.PackagingId);

            return new APIResult<List<PackagingModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询包材信息",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------包材图片PackagingpicModel-------------------------------------------------------------------
        /// <summary>
        /// 创建包材图片
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreatePackagingpic(PackagingpicModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建包材图片成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建包材图片失败");
            }
        }

        /// <summary>
        /// 查询包材图片
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<PackagingpicModel>> GetPackagingpicAll(int id)
        {
            var list = _db.Queryable<PackagingpicModel>().Where(x => x.RId == id).OrderByDescending(x => x.PackagingpicId);

            return new APIResult<List<PackagingpicModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询包材图片",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------屠宰企业ProcessingCommpany-------------------------------------------------------------------
        /// <summary>
        /// 创建深加工企业
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateProcessingCommpany(ProcessingCommpany e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建深加工企业成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建深加工企业失败");
            }
        }

        /// <summary> 
        /// 查询深加工企业
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<ProcessingCommpany>> GetProcessingCommpanyAll(int id)
        {
            var list = _db.Queryable<ProcessingCommpany>().Where(x => x.RId == id).OrderByDescending(x => x.ProComId);

            return new APIResult<List<ProcessingCommpany>>()
            {
                Code = APIEnum.成功,
                Message = "查询深加工企业",
                Data = list.ToList(),
            };
        }

        //---------------------------------------------------屠宰企业图片ProcessingCommpany-------------------------------------------------------------------
        /// <summary>
        /// 创建深加工企业图片
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        [HttpPost]
        public APIResult<int> CreateProcessingpic(ProcessingpicModel e)
        {
            int r = _db.Insertable(e).ExecuteReturnIdentity();
            if (r > 0)
            {
                return APIResult<int>.Success("创建深加工企业图片成功", r);
            }
            else
            {
                return APIResult<int>.Fail("创建深加工企业图片失败");
            }
        }

        /// <summary> 
        /// 查询深加工企业图片
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult<List<ProcessingpicModel>> GetProcessingpicAll(int id)
        {
            var list = _db.Queryable<ProcessingpicModel>().Where(x => x.RId == id).OrderByDescending(x => x.ProcessingpicId);

            return new APIResult<List<ProcessingpicModel>>()
            {
                Code = APIEnum.成功,
                Message = "查询深加工企业图片",
                Data = list.ToList(),
            };
        }
    }
}
